<?php



class RedisApi extends ApiBase{
	private static $handle = null;
	private static $conf = null;


	/**
	 * 构造函数，初始化插件
	 */
	public function __construct() {
		parent::__construct();
		
		
		if(is_null(self::$handle)){

			$conf = n_confGet('redis');
			if(!$conf['state']){
				throw new PException("conf:读取失败");
			}
			
			self::$conf = $conf['data'];

			// foreach($conf as $key=>$val){
				// self::$handle['db'.$key] = new MysqlDriver($val['host'],$val['user'],$val['pwd'],$val['dbname']);
				// self::$handle['db'.$key]->exec("set names UTF8");
			// }
			
		}

		// echo "redis construct";
		// var_dump($conf);
	}

	
	public function __get($key){
		if(isset(self::$handle[$key])){
			return self::$handle[$key];
		}
		
				
		if(!isset(self::$conf[$key])){
			throw new PException("找不到redis配置:{$key}");
		}

		self::$handle[$key] = new RedisDriver(self::$conf[$key]['host'], self::$conf[$key]['port'], $key);
		// self::$handle[$key]->connect(self::$conf[$key]['host'],self::$conf[$key]['port']);
		// self::$handle[$key]->connect('10.11.161.41','8888');
		return self::$handle[$key];
	}

}
